package com.aishua.fire.controller.sysmanager;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import com.aishua.fire.common.anno.ModuleService;
import com.aishua.fire.common.constant.BigMenuConstants;
import com.aishua.fire.common.constant.ModuleConstants;
import com.aishua.fire.entity.dict.AddDictInfo;
import com.aishua.fire.entity.dict.UpdateDictInfo;
import com.aishua.fire.jpa.entity.DictHelp;
import com.aishua.fire.jpa.entity.Dictionary;
import com.aishua.fire.mapper.dto.DictDto;
import com.aishua.fire.service.DictHelpService;
import com.aishua.fire.service.DictService;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;


@Api(value = "字典配置信息操作相关",tags = {"字典配置信息操作相关接口"})
@RestController
@Slf4j
public class SystemDictController {
	
	@Autowired
	private DictService dictService;
	@Autowired
	private DictHelpService dictHelpService;

	@ModuleService(totalModule=BigMenuConstants.systemManager,moduleName=ModuleConstants.dictConfig)
	@ApiOperation(value="添加_字典配置信息")
	@PostMapping(value = {"/dict"} )
	public String add(@RequestBody AddDictInfo dictInfo) {
		log.info("添加字典配置信息信息:{}",dictInfo);
		return dictService.save(dictInfo);
    }
	
	@ModuleService(totalModule=BigMenuConstants.systemManager,moduleName=ModuleConstants.dictConfig)
	@ApiOperation(value="删除_字典配置信息")
	@DeleteMapping(value = {"/dict/{dictValue}"} )
	public void delete(@PathVariable @ApiParam(name="字典配置信息表id",value="类如:0000",required=true) String dictValue) {
		log.info("删除字典配置信息表id:{}",dictValue);
		dictService.deleteDict(dictValue);
    }
	
	@ModuleService(totalModule=BigMenuConstants.systemManager,moduleName=ModuleConstants.dictConfig)
	@ApiOperation(value="修改_字典配置信息")
	@PutMapping(value = {"/dict"} )
	public void update(@RequestBody UpdateDictInfo updatedictInfo) {
		log.info("修改字典配置信息信息:{}",updatedictInfo);
		dictService.update(updatedictInfo);
    }
	
	@ModuleService(totalModule=BigMenuConstants.systemManager,moduleName=ModuleConstants.dictConfig)
	@ApiOperation(value="查询_字典配置详情信息")
	@GetMapping(value = {"/dict/{dictValue}"} )
	public DictDto get(@PathVariable("dictValue") @ApiParam(name="字典配置信息dictValue",value="类如:0000",required=true) String dictValue) {
		log.info("查询字典配置信息id:{}",dictValue);
		return dictService.findDictId(dictValue);
    }
	
	@ModuleService(totalModule=BigMenuConstants.systemManager,moduleName=ModuleConstants.dictConfig)
	@ApiOperation(value="查询_根据类别查询所有正在使用中的字典信息列表")
	@GetMapping(value = {"/dictType/{teamValue}"})
	public List<DictDto> findAllUsingByType(@PathVariable("teamValue") String teamValue) {
		log.info("查询字典组teamValue:{}",teamValue);
		return dictService.findAllUsingByType(teamValue);
	}
	
	@ModuleService(totalModule=BigMenuConstants.systemManager,moduleName=ModuleConstants.dictConfig)
	@ApiOperation(value="查询_字典信息列表")
	@GetMapping(value = {"/dictList"} )
	public List<DictDto> dictList() {
		log.info("查询字典信息列表");
		return dictService.searchList();
	}
	
	@ModuleService(totalModule=BigMenuConstants.systemManager,moduleName=ModuleConstants.dictConfig)
	@ApiOperation(value="查询_字典帮助列表信息")
	@GetMapping(value = {"/dictHelpList"} )
	public List<DictHelp> dictHelpList() {
		log.info("查询字典帮助列表信息");
		return dictHelpService.getDictHelp();
	}
	
	@ModuleService(totalModule=BigMenuConstants.systemManager,moduleName=ModuleConstants.dictConfig)
	@ApiOperation(value="查询_根据字典Key查询字典信息")
	@GetMapping(value = {"/dictionaryList/{teamValue}"} )
	public List<Dictionary> getDictionary(@PathVariable("teamValue") String teamValue) {
		log.info("查询字典列表信息");
		return dictService.findDictName(teamValue);
	}
	
}
